#include "ViewController.h"
#include "View.h"
#include "DebugLog.h"

ViewController::ViewController( View* v ) : _view( ( v ) ? v : new View() )
{
	//TRACEFUNC
}

ViewController::~ViewController( )
{
	//TRACEFUNC
	
	//if ( View* super = view()->superView() ) super->removeSubView( view() );
	
	delete view();
}

void ViewController::view( View* v )
{
	//TRACEFUNC
		
	if ( view() != v )
	{
		// remove self view from view tree
		if ( view() )
		{
			if ( View* par = view()->superView() )
			{
				par->removeSubView( view() );
			}
		}

		delete view();
		_view = v;
	}
}

View* ViewController::view() 
{
	if ( !_view )
	{
		_view = new View();
	}
	return _view;
}